package alogrithm;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lbw
 * @version 1.0
 * @date 2021/10/18 11:54
 */
public class TowSum {
    public int[] twoSum(int[] numbers, int target) {
        // write code here
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < numbers.length; ++i) {
            if (map.containsKey(target - numbers[i])) {
                return new int[]{map.get(target - numbers[i]), i + 1};
            } else {
                map.put(numbers[i], i + 1);
            }
        }
        return new int[]{-1, -1};
    }
}
